package day018.thread.demo3;

public class Ticket implements Runnable {
    private int ticketCount=100;

    @Override
    public void run() {
        while (true) {
            if (method()) {
                break;
            }
        }
    }

    private synchronized boolean method() {
        if (ticketCount <= 0) {
            return true;
        } else {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            ticketCount--;
            System.out.println(Thread.currentThread().getName() + "卖出一张票，剩下" + ticketCount + "张");
            return false;
        }
    }
}
